import request from "@/utils/request";

const USER_BASE_URL = "/core/logistics";

const parkingSpaceInquiryApi = {
  /**
   * 分页查询车位信息
   * @param params params 查询参数
   * @returns
   */
  pageQuery(params: parkingSpaceInquiryQuery): Promise<PageResult<parkingSpaceInquiryResult[]>> {
    let query = encodeURIComponent(JSON.stringify(params));
    return request({
      url: `${USER_BASE_URL}/parking/query?object=${query}`,
      method: "get",
    });
  },
  /**
   * 装车完成
   * @param params 配送单维护对象
   * @returns 配送单维护对象
   * @example
   */
  completeLoading: (parkingSpaceId: string, sourceCode: string) => {
    return request<any, any>({
      url: `${USER_BASE_URL}/parking/complete`,
      method: "post",
      data: {
        parkingSpaceId,
        sourceCode,
      },
    });
  },
  /**
   * 新增或修改车位信息
   *
   */
  saveOrUpdate(data: parkingSpaceInquiryUpdate) {
    return request({
      url: `${USER_BASE_URL}/parking/saveOrUpdate`,
      method: "post",
      data,
    });
  },
};
export default parkingSpaceInquiryApi;

// 车位查询接口参数
export interface parkingSpaceInquiryQuery extends PageQuery {
  spotType: number; //车位类型 0-装车车位 1-卸车车位
}

//查询接口返回数据
export interface parkingSpaceInquiryResult {
  licensePlate: string;
  licensePlateList: parkingSpaceInquiry[];
  parkingLocation: string;
  spotType: number; //车位类型 0-装车车位 1-卸车车位
}

export interface parkingSpaceInquiry {
  createName: string;
  createTime: string;
  createUser: number;
  driverName: string;
  driverPhone: string;
  finishTime: string;
  id: number;
  isDelete: false;
  licensePlate: string;
  modifyName: string;
  modifyTime: string;
  modifyUser: number;
  parkingLocation: string;
  sort: number;
  sourceCode: string;
  spotType: number;
  status: number;
}

/**
 * 修改请求参数
 * @example {
 *   parking: "1",
 *   licensePlate: "粤A123456",
 *   sourceCode: "1001"
 * }
 *
 */
export interface parkingSpaceInquiryUpdate {
  parkingLocation: string; //车位
  licensePlate: string; //车牌号
  sourceCode: string; //来源编码
  spotType: number; //车位类型 0-装车车位 1-卸车车位
}
